Backup Squarespace code Injections to Github
工作流概述
这是一个包含17个节点的复杂工作流,主要用于自动化处理各种任务。
工作流源代码
{
"id": "eB4rTdZFvrdKK5VP",
"meta": {
"instanceId": "e634e668fe1fc93a75c4f2a7fc0dad807ca318b79654157eadb9578496acbc76",
"templateCredsSetupCompleted": true
},
"name": "Backup Squarespace code Injections to Github",
"tags": [
{
"id": "oIxDbURnjwrJFwau",
"name": "Squarespace",
"createdAt": "2025-03-06T05:49:51.612Z",
"updatedAt": "2025-03-06T05:49:51.612Z"
}
],
"nodes": [
{
"id": "e0811eee-5bfe-4e48-8bd2-76b415261e93",
"name": "On clicking 'execute'",
"type": "n8n-nodes-base.manualTrigger",
"position": [
820,
486.1164603611751
],
"parameters": {},
"typeVersion": 1
},
{
"id": "e48028e0-d88a-4681-84b8-fa17fe695344",
"name": "Loop Over Items",
"type": "n8n-nodes-base.splitInBatches",
"position": [
2380,
580
],
"parameters": {
"options": {},
"batchSize": 2
},
"typeVersion": 3,
"alwaysOutputData": true
},
{
"id": "0dd2a2b1-8c19-4d7a-a631-d934320bcf74",
"name": "Schedule Trigger",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
820,
686.1164603611751
],
"parameters": {
"rule": {
"interval": [
{
"field": "hours",
"hoursInterval": 2
}
]
}
},
"typeVersion": 1.2
},
{
"id": "a1bc1313-5993-4d10-b322-0b31dd005d00",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
380,
240
],
"parameters": {
"color": 4,
"width": 371.1995072042308,
"height": 600.88409546716,
"content": "## Backup to GitHub
This workflow will backup Squarespace header & footer Injections to Github
### Setup
👉 Edit the Squarespace node to place the website URL there
👉 Open `Globals` node and update the values below 👇
- **repo.owner:** your Github username
- **repo.name:** the name of your repository
- **repo.path:** the folder to use within the repository.
If your username was `john-doe` and your repository was called `n8n-backups` and you wanted the injections to go into a `squarespace-backup` folder you would set:
- repo.owner - john-doe
- repo.name - n8n-backups
- repo.path - squarespace-backup/
Each site's injections will be added into seperate folder
"
},
"typeVersion": 1
},
{
"id": "125b425c-1f59-4984-8658-e57d3145cccd",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
780,
400
],
"parameters": {
"color": 7,
"width": 1066,
"height": 435,
"content": "## Main workflow loop"
},
"typeVersion": 1
},
{
"id": "626d534f-f2fb-4493-af58-0f5e309c58d4",
"name": "Get Squarespace data",
"type": "n8n-nodes-base.httpRequest",
"position": [
1140,
600
],
"parameters": {
"url": "https://beyondspace.studio",
"options": {},
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "format",
"value": "page-context"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "e2b1481e-b9de-4006-92b6-4677b4e11213",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
1080,
460
],
"parameters": {
"color": 4,
"width": 170,
"height": 120,
"content": "## Edit this node 👇
Squarespace URL"
},
"typeVersion": 1
},
{
"id": "e8fb73af-9999-43cd-9857-564a049b2579",
"name": "If",
"type": "n8n-nodes-base.if",
"position": [
3060,
600
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "0f6f0b04-6d87-47fb-bee7-df2c93283d1c",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.error }}",
"rightValue": "The resource you are requesting could not be found"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "679cd20a-c124-4f89-aea3-14dc5a739826",
"name": "Clean up Footers",
"type": "n8n-nodes-base.code",
"position": [
1620,
460
],
"parameters": {
"jsCode": "const cheerio = require('cheerio');
try {
const $footers = cheerio.load($input.first().json.value);
let sqsFooters = '';
/** CLEAN FOOTERS */
// Remove all elements after and including .social-icons-svg
const socialIcons = $footers('[data-usage=social-icons-svg]');
if (socialIcons.length) {
socialIcons.nextAll().remove(); // Remove everything after it
socialIcons.remove(); // Remove the element itself
}
// Extract cleaned-up footer content
$footers('head').each((i, el) => {
sqsFooters += $footers(el).html();
});
// Remove excessive newlines caused by removed elements
sqsFooters = sqsFooters.replace(/\n{2,}/g, '\n').trim();
return [{
...$input.first().json,
value: sqsFooters,
}];
} catch (error) {
console.error('Error processing Squarespace footers:', error);
// Return the original full input in case of failure
return [{
...$input.first().json,
value: $input.first().json.value,
}];
}
"
},
"typeVersion": 2
},
{
"id": "92150603-acbd-41bf-8cf2-b6891e08e326",
"name": "Clean up Headers",
"type": "n8n-nodes-base.code",
"position": [
1620,
680
],
"parameters": {
"jsCode": "const cheerio = require('cheerio');
try {
const $headers = cheerio.load($input.first().json.value);
let sqsHeaders = '';
// Find the Squarespace CSS link that marks the start of relevant headers
const $headerStart = $headers('link[href*=\"static1.squarespace.com/static/versioned-site-css\"][href*=\"site.css\"]');
// Remove all elements before and including the header start
if ($headerStart.length) {
$headers($headerStart).prevAll().remove();
$headers($headerStart).remove();
}
// Remove Squarespace's cookie banner script (marks the end) and any following elements
const cookieBannerScript = $headers('script').filter((_, el) =>
$headers(el).html().includes('Static.COOKIE_BANNER_CAPABLE = true;')
);
if (cookieBannerScript.length) {
cookieBannerScript.nextAll().remove(); // Remove everything after it
cookieBannerScript.remove(); // Remove the script itself
}
// Extract cleaned-up headers
$headers('head').each((i, el) => {
sqsHeaders += $headers(el).html();
});
// Remove any unwanted comments or placeholders
sqsHeaders = sqsHeaders.replace('<!-- End of Squarespace Headers -->', '');
// Remove excessive newlines caused by removed elements
sqsHeaders = sqsHeaders.replace(/\n{2,}/g, '\n').trim();
return [{
...$input.first().json,
value: sqsHeaders,
}];
} catch (error) {
console.log('Error processing Squarespace headers:', error);
// Return the original full input in case of failure
return [{
...$input.first().json,
value: $input.first().json.value,
}];
}
"
},
"typeVersion": 2
},
{
"id": "a777d9ca-2841-47dc-a4d5-5ae36713d4a2",
"name": "Get Footer Injection",
"type": "n8n-nodes-base.set",
"position": [
1380,
460
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "49e2fd3c-d46e-42a0-84d5-578166c1fbae",
"name": "value",
"type": "string",
"value": "={{ $json[\"squarespace-footers\"] }}"
},
{
"id": "b2de857c-2120-4e7e-81d8-bb73dd059261",
"name": "id",
"type": "string",
"value": "footers"
},
{
"id": "14de0bc4-6a40-488d-a17e-0ff940a8d38b",
"name": "name",
"type": "string",
"value": "footers"
},
{
"id": "065cb5cd-b9fd-4aab-90be-5191e96d9b91",
"name": "timestamp",
"type": "string",
"value": "={{ new Date().getTime() }}"
},
{
"id": "41016a39-abf7-46ce-88b9-985553210983",
"name": "domain",
"type": "string",
"value": "={{ ($json.website.primaryDomain || $json.website.authenticUrl || $json.website.internalUrl).replace(/^(?:https?:\/\/)?(?:www\.)?/, '') }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "c8cdf09b-0218-4dbc-9564-e84d123ad5d7",
"name": "Get Header Injection",
"type": "n8n-nodes-base.set",
"position": [
1380,
680
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "49e2fd3c-d46e-42a0-84d5-578166c1fbae",
"name": "value",
"type": "string",
"value": "={{ $json[\"squarespace-headers\"] }}"
},
{
"id": "3d64cbd1-d571-4b59-b9cc-d6d0cb9f1dda",
"name": "id",
"type": "string",
"value": "headers"
},
{
"id": "42d56c77-3f2b-4ea6-b3c9-754e293c0615",
"name": "name",
"type": "string",
"value": "headers"
},
{
"id": "b3d13c06-6a4a-4478-ad14-8e0b7a2998e0",
"name": "timestamp",
"type": "string",
"value": "={{ new Date().getTime() }}"
},
{
"id": "b0977682-f135-4546-a390-0a3777907e4f",
"name": "domain",
"type": "string",
"value": "={{ ($json.website.primaryDomain || $json.website.authenticUrl || $json.website.internalUrl).replace(/^(?:https?:\/\/)?(?:www\.)?/, '') }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "7ca88a4d-f438-4d3a-b3ce-e66f1dd3ae00",
"name": "Edit Injection data",
"type": "n8n-nodes-base.github",
"position": [
2840,
600
],
"parameters": {
"owner": {
"__rl": true,
"mode": "name",
"value": "={{ $json.repo.owner }}"
},
"filePath": "={{ $json.repo.path }}{{ $('Loop Over Items').item.json.id }}.html",
"resource": "file",
"operation": "edit",
"repository": {
"__rl": true,
"mode": "name",
"value": "={{ $json.repo.name }}"
},
"fileContent": "={{ $('Loop Over Items').item.json.value }}",
"commitMessage": "=Backup at {{ new DateTime($('Loop Over Items').item.json.timestamp) }}"
},
"credentials": {
"githubApi": {
"id": "3FYHiPFtycAFT8V0",
"name": "GitHub account"
}
},
"typeVersion": 1,
"continueOnFail": true,
"alwaysOutputData": true
},
{
"id": "34ae1cf2-0abb-4fec-b60c-35c44f92020d",
"name": "Create Injection data",
"type": "n8n-nodes-base.github",
"position": [
3280,
620
],
"parameters": {
"owner": {
"__rl": true,
"mode": "name",
"value": "={{ $('Globals').item.json.repo.owner }}"
},
"filePath": "={{ $('Globals').item.json.repo.path }}{{ $('Loop Over Items').item.json.id }}.html",
"resource": "file",
"repository": {
"__rl": true,
"mode": "name",
"value": "={{ $('Globals').item.json.repo.name }}"
},
"fileContent": "={{ $('Loop Over Items').item.json.value }}",
"commitMessage": "=Backup at {{ new DateTime($('Loop Over Items').item.json.timestamp) }}"
},
"credentials": {
"githubApi": {
"id": "3FYHiPFtycAFT8V0",
"name": "GitHub account"
}
},
"typeVersion": 1,
"continueOnFail": true,
"alwaysOutputData": true
},
{
"id": "40ae14ee-ce39-4706-898c-51957f52328d",
"name": "Globals",
"type": "n8n-nodes-base.set",
"position": [
2640,
600
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "6cf546c5-5737-4dbd-851b-17d68e0a3780",
"name": "repo.owner",
"type": "string",
"value": "BeyondspaceStudio"
},
{
"id": "452efa28-2dc6-4ea3-a7a2-c35d100d0382",
"name": "repo.name",
"type": "string",
"value": "n8n-backup"
},
{
"id": "81c4dc54-86bf-4432-a23f-22c7ea831e74",
"name": "repo.path",
"type": "string",
"value": "=squarespace-backup/{{ $json.domain }}/"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "d20a5274-66e8-4053-b29d-e814e67a3f0e",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
2600,
480
],
"parameters": {
"color": 4,
"width": 150,
"height": 80,
"content": "## Edit this node 👇"
},
"typeVersion": 1
},
{
"id": "db43654b-22bc-4c0e-9b6a-6f1dded7deb8",
"name": "Merge Injections",
"type": "n8n-nodes-base.merge",
"position": [
2140,
580
],
"parameters": {},
"typeVersion": 3
}
],
"active": true,
"pinData": {},
"settings": {},
"versionId": "dfe7ec9f-5b7a-4a9c-8b53-b0cc4bcc2d27",
"connections": {
"If": {
"main": [
[
{
"node": "Create Injection data",
"type": "main",
"index": 0
}
],
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Globals": {
"main": [
[
{
"node": "Edit Injection data",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[],
[
{
"node": "Globals",
"type": "main",
"index": 0
}
]
]
},
"Clean up Footers": {
"main": [
[
{
"node": "Merge Injections",
"type": "main",
"index": 0
}
]
]
},
"Clean up Headers": {
"main": [
[
{
"node": "Merge Injections",
"type": "main",
"index": 1
}
]
]
},
"Merge Injections": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "Get Squarespace data",
"type": "main",
"index": 0
}
]
]
},
"Edit Injection data": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"Get Footer Injection": {
"main": [
[
{
"node": "Clean up Footers",
"type": "main",
"index": 0
}
]
]
},
"Get Header Injection": {
"main": [
[
{
"node": "Clean up Headers",
"type": "main",
"index": 0
}
]
]
},
"Get Squarespace data": {
"main": [
[
{
"node": "Get Header Injection",
"type": "main",
"index": 0
},
{
"node": "Get Footer Injection",
"type": "main",
"index": 0
}
]
]
},
"Create Injection data": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"On clicking 'execute'": {
"main": [
[
{
"node": "Get Squarespace data",
"type": "main",
"index": 0
}
]
]
}
}
}
功能特点
- 自动检测新邮件
- AI智能内容分析
- 自定义分类规则
- 批量处理能力
- 详细的处理日志
技术分析
节点类型及作用
- Manualtrigger
- Splitinbatches
- Scheduletrigger
- Stickynote
- Httprequest
复杂度评估
配置难度:
维护难度:
扩展性:
实施指南
前置条件
- 有效的Gmail账户
- n8n平台访问权限
- Google API凭证
- AI分类服务订阅
配置步骤
- 在n8n中导入工作流JSON文件
- 配置Gmail节点的认证信息
- 设置AI分类器的API密钥
- 自定义分类规则和标签映射
- 测试工作流执行
- 配置定时触发器(可选)
关键参数
| 参数名称 | 默认值 | 说明 |
|---|---|---|
| maxEmails | 50 | 单次处理的最大邮件数量 |
| confidenceThreshold | 0.8 | 分类置信度阈值 |
| autoLabel | true | 是否自动添加标签 |
最佳实践
优化建议
- 定期更新AI分类模型以提高准确性
- 根据邮件量调整处理批次大小
- 设置合理的分类置信度阈值
- 定期清理过期的分类规则
安全注意事项
- 妥善保管API密钥和认证信息
- 限制工作流的访问权限
- 定期审查处理日志
- 启用双因素认证保护Gmail账户
性能优化
- 使用增量处理减少重复工作
- 缓存频繁访问的数据
- 并行处理多个邮件分类任务
- 监控系统资源使用情况
故障排除
常见问题
邮件未被正确分类
检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。
Gmail认证失败
确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。
调试技巧
- 启用详细日志记录查看每个步骤的执行情况
- 使用测试邮件验证分类逻辑
- 检查网络连接和API服务状态
- 逐步执行工作流定位问题节点
错误处理
工作流包含以下错误处理机制:
- 网络超时自动重试(最多3次)
- API错误记录和告警
- 处理失败邮件的隔离机制
- 异常情况下的回滚操作